﻿@using Cxuu.Common
@model IEnumerable<ViewCacheModel>
@{
    ViewData["Title"] = "操作日志";
}
<div class="content-top-nav">
    <div class="layui-row">
        <div class="layui-col-md11">
            <h3 style="color:#444">
                <i class="layui-icon layui-icon-home"></i>
                @ViewData["Title"]
            </h3>
        </div>
        <div class="layui-col-md1" style="text-align:right;">

        </div>
    </div>
    <hr>
</div>

<div class="layui-fluid" style="margin-bottom:50px;">
    <script type="text/html" id="toolbarAE">
        <div class="layui-btn-container">
            @if (await Authorizer.AuthView(PermissionKeys.Attment_AddOrEdit))
            {
                <button class="layui-btn layui-btn-sm data-add-btn">上传新文件</button>
            }
        </div>
    </script>

    <table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>

    <script type="text/html" id="UserTpl">
        {{d.deptName}} -  {{d.nickname}}
    </script>

     <script type="text/html" id="ImgTpl">
        {{# if(d.ext ==".jpg" || d.ext ==".png" ){ }}
            <a lay-event="imgPreview">  <img src="{{d.url}}"  width="70" height="50"></a>
        {{# }else{ }}
            {{d.url}}
        {{#  } }}
    </script>

    <script type="text/html" id="currentTableBar">
        <div class="layui-btn-group">
        @if (await Authorizer.AuthView(PermissionKeys.Attment_Delete))
        {
                <a class="layui-btn layui-btn-sm layui-btn-danger data-count-delete" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</a>
        }
        </div>
    </script>

</div>

<script>
    layui.define(function () {
        var table = layui.table, $ = layui.jquery, form = layui.form;

        form.render();

        table.render({
            elem: '#currentTableId',
            url: '/Admin/Attment/Index?json=1',
            toolbar: '#toolbarAE',
            lineStyle: 'height:50px;',
            cols: [[
                { field: 'id', title: 'Id', width:80, align: "center"  },
                { field: 'url', title: '位置', templet: '#ImgTpl', align: "center" },
                { field: 'size', title: '大小(KB)', width: 120, sort: true, align: "center" },
                { field: 'filename', title: '原文件名' , width: 300},
                { field: 'ext', title: '类型', width: 100, sort: true, align: "center" },                
                { field: 'source', title: '上传位置', width: 150, align: "center" },
                { field: 'nickname', title: '上传用户', width: 220, templet: '#UserTpl', align: "center" },
                { field: 'time', title: '上传时间', width: 180, align: "center" },
                { title: '操作', width: 160, templet: '#currentTableBar', fixed: "right", align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 20,
            id: 'tableReload',
            page: true
        });

        // 监听添加操作
        $(".data-add-btn").on("click", function () {
            loadMain('/Admin/Attment/AddOrEdit');
            return false;
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('确定删除' + data.id + '附件吗？', {
                    btn: ['确定', '取消']
                }, function (index) {
                    $.post('/Admin/Attment/Delete?id=' + data.id, function (res) {
                        if (res.status == 1) {
                            layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                obj.del();
                                layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                        }
                    });
                });
            } else if (obj.event === 'imgPreview') {
                var img = "<img src='" + data.url + "' />";
                layer.open({
                    type: 1,
                    title: false, 
                    area: ['auto', 'auto'],
                    //area: [img.width + 'px', img.height + 'px'],
                    shadeClose: "true",
                    content: img
                });
                return false;
            }
        });

    });
</script>
